package com.argushealth.huang.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * 
 * @author guozhuhuang
 *
 */
public class ProxyAgent implements InvocationHandler {
	private Person person;
	
	public Object getInstance(Person person) {
		this.person = person;
		Class clazz = person.getClass();
		return Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), this);
	}

	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		System.out.println("----------调用方法前-----------");
		Object result = method.invoke(this.person, args);
		System.out.println("----------调用方法后-----------");
		return result;
	}
}
